<template lang="jade">
div
	div.return-bar(@click="back()")
		i.iconfont &#xe668;
		div.limitedname {{{item.name}}}

	div.detail-page

		ul.productlist.detail_top
			li
				div.title
					span.name {{item.name}}
					span.fr 起投金额:100元
				flexbox
					flexbox-item(style="-ms-flex: 1.7;flex: 1.7;-webkit-box-flex: 1.7;")
						span 借款金额
						b {{item.account}}元
					flexbox-item
						span 约定收益率
						b.mtxt {{item.borrow_apr}}%
					flexbox-item
						span 借款期限
						b {{item.borrow_period}}{{item.borrow_period_str}}

					flexbox-item
						a.p_btn_nob.tcenter {{item.status_str}}

				flexbox
					flexbox-item(:span="6")
						剩余可投金额:{{item.borrow_account_wait}}元
					flexbox-item
						progress(:percent="item.borrow_account_scale", :show-cancel="false")
					flexbox-item(:span="2")
						span.mtxt {{item.borrow_account_scale}}%



		ul.productdetail
			li
				i.iconfont &#xe6e0;
				span 还款方式
				span.fr {{item.borrow_style}}

			li
				i.iconfont &#xe644;
				span 已投人数
				span.fr {{item.number_of_bidders}}人

			li
				i.iconfont &#xe646;
				span 募资时间
				span.fr  {{item.time}}

			li
				i.iconfont &#xe645;
				span 保障方式
				span.fr {{item.guarantee}}

		ul.cbox.hl.producthl(style="margin-bottom: 5rem;")
			li
				a(v-link="{ path: '/invest/detail-sub/1?borrow_nid='+item.borrow_nid }")
					i
						img(src="../../assets/images/invest/detail-hl-icon1.png")
					span 借款信息
			li(v-link="{ path: '/invest/guarantee/'+item.borrow_nid }")
				a
					i
						img(src="../../assets/images/invest/detail-hl-icon2.png")
					span 还款保障
			li
				a(v-link="{ path: '/invest/detail-sub/3?borrow_nid='+item.borrow_nid }")
					i
						img(src="../../assets/images/invest/detail-hl-icon3.png")
					span 投资记录
			li
				a(v-link="{ path: '/invest/detail-sub/4?borrow_nid='+item.borrow_nid }")
					i
						img(src="../../assets/images/invest/detail-hl-icon4.png")
					span 还款计划



		section.form
			div
				div.postForm
					input.money(name="money",v-model="money",placeholder="请输入100的整数倍数，最低100元",autocomplete="off")
					input(type="hidden",name="borrow_nid",v-model="detailId")
					span.rmb 元
					ul.cbox
						li.balance
							span 可用余额￥
								b {{banlance}}
								元
							//span.est 10,000元3个预计收282.51元
						li.btn
							input.goPay(type="button",value="立即投标", @click="onSubmit()")



formpage(:url.sync="post_url", :rdata.sync="post_data")

</template>


<script>
import '../../assets/sass/invest/invest.scss'
import {Api_Recharge, c_borrow_detail, c_order_detail,Api_Tender} from '../../config/api'
import {Progress, Flexbox, FlexboxItem} from 'vux'
import FormPage from '../../components/common/form'

export default {

	data () {
		return {
			from:'',
			post_url: '',
			post_data:{},
			sub_Tender:Api_Tender,
			detailId: '',
			typeId:'',
			item: '',
			money: '',
			banlance: 0,
			busy:false,
			subForm:null,
			wx_share:{"title":'', "link":window.location.href, "img":'http://www.uximoney.com/themes/blue/img/logo-temp.png', "desc":''}
		}
	},
	components: {
		formpage:FormPage,
		Progress:Progress,
		Flexbox:Flexbox,
		FlexboxItem:FlexboxItem
	},
	methods: {
		back(){
			if(this.from==undefined || this.from=='' || this.from==null)
				this.$route.router.go('/invest/index?productype=current');
			else
				this.$route.router.go(this.from);

			//window.history.back();
		},

		getForm(){
			for(var a in this.$children){
				if(this.$children[a].name == 'form')
					this.subForm = this.$children[a];
			}
		},

		onSubmit: function () {
			if(this.busy){
				return;
			}

			var that = this;
			this.busy = true;
			this.$store.dispatch('setShowLoading', true);
			var data = {'borrow_nid': this.detailId, 'money': this.money, 'ajax': '1'}
			this.$http.post(Api_Tender, data,'').then(function (response) {
				this.busy = false;
				this.$store.dispatch('setShowLoading', false);
				var rs = response.data

				//console.log(rs);

				//return;
				if(!rs.status){
					alert(rs.msg);
					if(rs.msg == '请登录'){
						this.$route.router.go('/login')
					}
				}else{

					this.getForm();
					this.subForm.show = true
					this.post_url = rs.action_url
					this.post_data.RequestData = rs.RequestData
					this.post_data.transCode = rs.transCode
					this.subForm.submit();

				}
			}, function (response) {
					console.log(response)
			});

		},

		fetch: function () {
			var that = this, url = "";

			//if(this.typeId=='1')
				//url = '&name_no='+this.detailId;
			//else
				url = '&borrow_nid='+this.detailId;
				this.$store.dispatch('setShowLoading', true);

			this.$http({url: c_borrow_detail+url, method: 'get'}).then(function (response) {
				this.$store.dispatch('setShowLoading', false);
				that.item = response.data.data
				that.banlance = response.data.banlance
				document.title = that.item.name + " - 有喜财富投标理财"

				//微信分享
				this.wx_share.desc = "年利率:"+that.item.borrow_apr + "%, 期限:"+that.item.borrow_period + that.item.borrow_period_str
				this.wx_share.title = "我在有喜发现了一个不错的理财项目，你也来看看吧！"
				this.wx_share.img = that.item.borrow_pawn_app_url;
				this.global.wxset(this.wx_share)

			}, function (response) {
					console.log(response)
			});
		}
	},
	route: {
		/*data:function(){
			document.title = "有喜财富 - 手机版" ;
		},*/
		activate ( transition ) {

			this.detailId = transition.to.params.detailId
			this.typeId = transition.to.params.typeId
			this.from = transition.to.query.from
			console.log(this.from)
			transition.next();
			this.fetch()
		}
	}
}
</script>
